﻿/*************************************************************************
	Copyright (C) 2009-2010 欣风工作室    
	All rights reserved
	
	CLR版本:			2.0.50727.4959
	命名空间名称:		替换文本1
	文件名:				clsFileManager
	创建时间:			2011/5/5 14:48:29
	作者:				我烤
	QQ:					8230707
	E-Mail:				xfgzskof@163.com
	
	修改日志:
	
*************************************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;

namespace 街头篮球自动购买道具
{
    class TextManager
    {
        /// <summary>
        /// 打开文本文件并返回内容
        /// </summary>
        /// <param name="fileName">文件名称</param>
        /// <returns>文本内容</returns>
        public static string OpenFile(string fileName)
        {
            string result = "";
            StreamReader reader = null;
            try
            {
                reader = new StreamReader(fileName, Encoding.Default);
                result = reader.ReadToEnd();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                reader.Close();
            }
            return result;
        }

        public static bool SaveFile(string fileName, string strContent)
        {
            return SaveFile(fileName, strContent, true);
        }
        /// <summary>
        /// 保存文本文件
        /// </summary>
        /// <param name="fileName">文件名</param>
        /// <param name="strContent">文本内容</param>
        /// <returns>是否保存成功</returns>
        public static bool SaveFile(string fileName, string strContent,bool isCute)
        {
            bool result = false;
            StreamWriter writer = null;
            try
            {
                writer = new StreamWriter(fileName, false, Encoding.Default);

                writer.Write(strContent);
                writer.Flush();
                result = true;
                if (isCute) MessageBox.Show("保存成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                writer.Close();
            }
            return result;
        }
    }
}
